package fr.ralmn.OgameDroid;

import android.app.ActionBar;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
import android.widget.Toast;
import fr.ralmn.OgameDroid.Object.Technologie;
import fr.ralmn.OgameDroid.Ressource.Listing;
import fr.ralmn.OgameDroid.list.Adapter.TechoArrayAdapter;

public class TechnoListActivity extends ListActivity {
	public static TechoArrayAdapter a;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		a = new TechoArrayAdapter(this, Listing.getTechnologie());
		setListAdapter(a);
		ActionBar bar = getActionBar();
		bar.setDisplayShowHomeEnabled(true);
		bar.setHomeButtonEnabled(true);

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {

		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.main, menu);
		ActionBar bar = getActionBar();
		bar.setDisplayShowHomeEnabled(true);
		bar.setHomeButtonEnabled(true);

		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		super.onOptionsItemSelected(item);
		switch (item.getItemId()) {
		case R.id.menu_WikiGroup:
			Toast.makeText(this, "Selectionner l'item voulue",
					Toast.LENGTH_SHORT);
			break;

		case R.id.wg_techno:
			Intent it = new Intent(TechnoListActivity.this,
					TechnoListActivity.class);
			startActivity(it);
			break;

		case R.id.wg_ressource:
			Intent ir = new Intent(TechnoListActivity.this,
					RessourcesListActivity.class);
			startActivity(ir);
			break;
		case R.id.menu_exit:
			finish();
			break;

		default:
			break;
		}

		return true;

	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		Technologie te = a.getItem(position);
		// TechnoActivity.technologie = t;
		Bundle t = new Bundle();
		t.putString("technologie", te.getName());
		Intent i = new Intent(TechnoListActivity.this, TechnoActivity.class);
		i.putExtras(t);
		startActivity(i);

	}

}
